package top.hjcwzx.wrench.trigger;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.hjcwzx.wrench.limiter.annotation.IpRateLimiter;
import top.hjcwzx.wrench.limiter.annotation.KeyRateLimiter;
import top.hjcwzx.wrench.limiter.enums.AlgorithmStrategyEnum;
import top.hjcwzx.wrench.limiter.enums.KeyStrategyEnum;


@RestController
@RequestMapping("/index")
public class IndexController {


    @KeyRateLimiter(key = "test",permitsPerSecond = 10,
            algorithmStrategy = AlgorithmStrategyEnum.LEAKY_BUCKET,fallbackMethod = "test")
    @GetMapping("/get")
    public String index(){
        return "获取成功";
    }

    @IpRateLimiter
    @KeyRateLimiter
    @GetMapping("/get2")
    public String index2(){
        return "获取成功";
    }

    @KeyRateLimiter(key = "#userId",keyStrategy = KeyStrategyEnum.SPEL)
    @GetMapping("/get3/{userId}")
    public String index3(@PathVariable("userId") String userId){
        return userId+"获取成功";
    }

    @IpRateLimiter(fallbackMethod = "test")
    @GetMapping("/get5")
    public String index5(){
        return "获取成功";
    }

    @IpRateLimiter(fallbackBean = ExceBean.class, fallbackMethod = "test")
    @GetMapping("/get6")
    public String index6(){
        return "获取成功";
    }

    public String test(){
        return "限流了";
    }





}
